package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportUserLoginLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportUserLoginLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-07-06 10:59:05
 */
public class TransportUserLoginLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportUserLoginLogConverts.class);

    public static List<TransportUserLoginLogDTO> convert(List<TransportUserLoginLog> transportUserLoginLogList) {
        if (CollectionUtils.isEmpty(transportUserLoginLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportUserLoginLogDTO> transportUserLoginListResult = Lists.newArrayList();
        for (TransportUserLoginLog transportUserLoginLog : transportUserLoginLogList) {
            transportUserLoginListResult.add(convert(transportUserLoginLog));
        }
        return transportUserLoginListResult;
    }

    public static TransportUserLoginLogDTO convert(TransportUserLoginLog transportUserLoginLog) {
        try {
            return BeanUtils.copy(transportUserLoginLog, TransportUserLoginLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportUserLogin到TransportUserLoginDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserLogin到TransportUserLoginDTO转换失败", e);
        }
    }

    public static TransportUserLoginLog convert(TransportUserLoginLogDTO transportUserLoginLogDTO) {
        try {
            return BeanUtils.copy(transportUserLoginLogDTO, TransportUserLoginLog.class);
        } catch (Exception e) {
            LOG.error("TransportUserLoginDTO到TransportUserLogin转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUserLoginDTO到TransportUserLogin转换失败", e);
        }
    }
}